package  Classes.LevelManagement
{
	import Classes.Utils.xmlLoader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.media.Camera;
	import flash.net.URLLoader;
	/**
	 * ...
	 * @author Rodrigo Forti & Rafael Bringel
	 */
	public class LevelManager extends MovieClip
	{
		private static var _current : 			Level_Base;
		private static var myLoader: 			xmlLoader;
		public var level: 						XML;
		private static var callUpdate:			Boolean
		
		public function LevelManager() 
		{
			
		}
		
		
		public static function get current(): Level_Base
		{
			return _current;
		}
		
		public static function set current(value : Level_Base): void
		{
			
			if (_current != null) 
				_current.terminate();
				
			myLoader = new xmlLoader(value.toString().substring(8, value.toString().length - 1));
			myLoader.addEventListener(Event.COMPLETE, dictonaryCompleted);
			
			_current = value;
		}
		
		public static function dictonaryCompleted(Evento:Event):void
		{
			trace("oi");
			if (_current != null)
			{
				_current.start(myLoader.objetos);
				callUpdate = true;
			}	
		}
		
		public static function update() : Boolean
		{
			if (_current == null) 
				return true;
					
			if (callUpdate)
			{
				_current.update();
				return false;
			}
			else
			{
				return true;
			}
		}
		
	}

}